<?php
/**
 * Author:   tangxiaowen
 * Email:    846506584@qq.com
 * Date:     2019/5/21 0013
 * Describe: 基础继承类.
 */

namespace app\api\controller\lishidai;

use think\Controller;
use think\Log;

class Base extends Controller
{
    public function __construct()
    {
        parent::__construct();

        //日志初始化保存地址
        $setPath = strtolower(request()->module().'/'.request()->controller().'/'.request()->action().'/');
        Log::init(['path' => LOG_PATH.$setPath, 'type' => 'file']);

        //验证请求方式
        if (!$this->isPost()) {
            errorResult($this->error);
        }

        //检测请求参是否缺失与签名是否正确
        $signObj = new Sign();
        if (!$signObj->isCheckSign()) {
            errorResult($signObj->getError());
        }
    }

    /**
     * 验证是否post请求
     *
     * @return bool
     */
    public function isPost()
    {
        if (strtolower(request()->action()) != 'waitingconfirm') {//订单等待确认的H5页面不需要验证post
            if (!request()->isPost()) {
                $this->error = '请求类型错误';

                return false;
            }
        }

        return true;
    }
}
